package bilibili.poly_.canshu;

public class PolyParameter {
    public static void main(String[] args) {
        Employee e1 = new Manager("zhangsan", 20000, 1000);
        Employee e2 = new Worker("lisi", 20000);

        double manager_salay = showEmpAnnual(e1);
        double worker_salay = showEmpAnnual(e2);
        System.out.println("经理年工资：" + manager_salay);
        System.out.println("员工年工资：" + worker_salay);

        System.out.println("===========");
        testWork(e1);
        testWork(e2);
    }

    // 获取任何员工对象的年工资
    public static double showEmpAnnual(Employee e) {
        return e.getAnnual();
    }

    // 如果是普通员工，则调用work方法，如果是经理，则调用manager方法
    public static void testWork(Employee e) {
        if (e instanceof Manager) {
            // 向下转型
            ((Manager) e).manager();
        } else if (e instanceof Worker) {
            // 向下转型
            ((Worker) e).work();
        }
    }
}
